<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="UTF-8"%>
<%
TopicDao topicDao =new TopicDaoImpl();
ReplyDao replyDao = new ReplyDaoImpl();
UserDao userDao = new UserDaoImpl();
BoardDao boardDao = new BoardDaoImpl();


int boardId = Integer.parseInt(request.getParameter("boardId")); // 取得板块id
int topicId = Integer.parseInt(request.getParameter("topicId")); // 取得主题id
int p = Integer.parseInt(request.getParameter("page"));
Board board = boardDao.findBoard(boardId); //板块
Topic topic = topicDao.findTopic(topicId); // 主题
User topicUser = userDao.findUser(topic.getUserId() ); // 主题作者
List listReply = replyDao.findListReply( p,topicId ); // 回复列表
int prep = p; // 上一页
int nextp = p; // 下一页
if(listReply.size() == 20) {
  nextp = p+1;
}
if( p>1 ){
  prep = p - 1;
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991221/loose.dtd">
<html>
  <head>
    <title>看帖</title>
    <meta http-equiv=Content-Type content="text/html;charset = UTF-8">
	  <link rel="stylesheet" type="text/css" href="styles.css">
  </head>
  
  <body>
    <!-- 用户信息、登录、注册 -->
    <div id="apDiv1">
			<div align ="center" class="STYLE1 textColor navbar-brand">
        <span class="font-weight-bold align-middle ml-3 d-inline-block">校</span>
        <span class="font-weight-bold align-middle ml-3 d-inline-block">园</span>
        <span class="font-weight-bold align-middle ml-3 d-inline-block">B</span>
        <span class="font-weight-bold align-middle ml-3 d-inline-block">B</span>
        <span class="font-weight-bold align-middle ml-3 d-inline-block">S</span>
        <span class="font-weight-bold align-middle ml-3 d-inline-block">系</span>
        <span class="font-weight-bold align-middle ml-3 d-inline-block">统</span>
      </div>
		</div>
		<%
			if(session.getAttribute("user")==null){
		%>
		<div class="STYLE4" id="apDiv2">
			您尚未<a href="login.jsp" target="_blank">登录</a>
			|
			<a href="reg.jsp" target="_blank" style="color:#fe7300;">注册</a>
		</div>
		<%
			}else{
				User loginUser=(User)session.getAttribute("user");
		%>
		<div class="STYLE4" id="apDiv2">
			您好:<%=loginUser.getUserName() %>
			&nbsp;|&nbsp;<a href="manage/doLogout.jsp">退出</a>
		</div>
		<%
		}
		%>

    <!-- 主体 -->
    <div><br/>
      <!-- 导航 -->
      <div>
        &gt;&gt;&gt;<b><a href="index.jsp" class="textColor">论坛首页</a></b>&gt;&gt;&gt;
        <b><a href="list.jsp?page=1&boardId=<%=boardId %>"><%=board.getBoardName() %></a></b>
      </div>
      <br/>
      <!-- 回复、新帖 -->
      <div>
        <a href="reply.jsp?topicId=<%=topicId%>&boardId=<%=boardId%>"><input type="submit" name="button" id="button" value="回复"/></a>
        <a href="post.jsp?boardId=<%=boardId %>"><input type="submit" name="button" id="button" value="发帖"/></a>
      </div>
      <!-- 翻页 -->
      <div>
        <a href="detail.jsp?page=<%=prep %>&boardId=<%=boardId %>&topicId=<%=topicId %>">上一页</a>
        |
        <a href="detail.jsp?page=<%=nextp %>&boardId=<%=boardId %>&topicId=<%=topicId %>">下一页</a>
      </div>
      <!-- 本页主题的标题 -->
      <div>
        <table width="100%" border="1" cellpadding="0" cellspacing="0">
          <tr>
            <th class="h transitional">本页主题:<%=topic.getTitle() %></th>
          </tr>
          <tr class="tr2">
            <td>
              &nbsp;
            </td>
          </tr>
        </table>
      </div>
      <!-- 主题 -->
      <%
      if(p==1){
      %>
      <div class="t">
        <table style="BORDER-TOP-WIDTH:0px;TABLE-LAYOUT:fixed"cellSpacing="0"cellPading="0"width="100%" border="1">
          <tr class="tr1">
            <th style="WIDTH:20%" class="transitional">
              <b><%=topicUser.getUserName() %></b><br/>
              <image src="image/head/<%=topicUser.getHead() %>"/><br/>
              注册时间:<%=topicUser.getRegTime() %><br/>
            </th>
            <th>
              <h4 align="left">主题:<%=topic.getTitle() %></h4>
              <div>
                <div align="left">内容:<%=topic.getContent() %></div>
              </div>
              <div class="tipad gray transitional">
                <div align="reght" class="transitional">
                  发表:[<%=topic.getPublishTime() %>]&nbsp;
                  最后修改:[<%=topic.getModifyTime() %>]
                </div>
              </div>
            </th> 
          </tr>
        </table>
      </div>
      <br><br>
      <!-- 回复 -->
      <%
      	}
      	for(int i = 0;i<listReply.size();i++){
      		Reply reply = (Reply)listReply.get(i);
      		User replyUser = (User)userDao.findUser(reply.getUserId());
       %>
       <div class="t">
       		<table style="BORDER - TOP - WIDTH:0PX; TABLE - LAYOUT:FIXED" cellingSpacing ="0" cellingPadding="0" width = "100%" border = "1" >
       			<tr class="tr1">
               <th style="WIDTH:20%" class="transitional">
                  <b>
                    <%=replyUser.getUserName() %>
                  </b>
                  <br/><br/>
                  <img src="image/head/<%=replyUser.getHead()%>"/><br/>
                  注册时间:<%=replyUser.getRegTime() %><br/>
              </th>
              <th>
                <h4 align="left">
                  <%=reply.getTitle() %>
                </h4>
                <div>
                  <div align="left">
                    <%=reply.getContent() %>
                  </div>
                </div>
                  <div class="tipad gray">
                    <div align="left" class="transitional">
                      发表:[<%=reply.getPublishTime() %>]&nbsp;
                      最后修改:[<%=reply.getModifyTime() %>]
                      <a href="manage/doDeleteReply.jsp?boardId=<%=boardId%>&topicId=<%=topicId%>&replyId=<%=reply.getReplyId()%>">[删除]</a>
                      <a href="update.jsp?tipType=reply&boardId=<%=boardId%>&topicId=<%=topicId%>&replyId=<%=reply.getReplyId()%>">[修改]</a>
                    </div>
                  </div>
              </th>
       			</tr>
       		</table>       
       </div>
       <%
       }
       %>


      <div>
        <a href="detail.jsp?page=<%=prep %>&boardId=<%=boardId %>&topicId=<%=topicId %>">上一页</a>
        |
        <a href="detail.jsp?page=<%=nextp %>&boardId=<%=boardId %>&topicId=<%=topicId %>">下一页</a>
      </div>
    </div>
  </body>
</html>
